/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


#include "backgroundwidget.h"
#include <services/configservice.h>
#include <appcommon.h>
#include <QTime>
#include <QPicture>
BackgroundWidget::BackgroundWidget(QWidget *parent) : QWidget(parent) {
//    mScene = new QGraphicsScene(this);
//    this->setScene(mScene);
    this->setContextMenuPolicy(Qt::NoContextMenu);
    Qt::WindowFlags flags = Qt::Window | Qt::FramelessWindowHint;
    this->setWindowFlags(flags);
//    this->setCacheMode(QGraphicsView::CacheBackground);
    mMessageLabel = new QLabel(this);
    mMessageLabel->setGeometry(430, 380, 200, 40);    
    mMessageLabel->setStyleSheet("color: white; font-size: 32px;");
    this->setObjectName("bg_widget");
}

void BackgroundWidget::showMessage(const QString &message) {
    mMessageLabel->setText(message);
    mMessageLabel->show();
}

void BackgroundWidget::hideMessage() {
    mMessageLabel->setText("");
    mMessageLabel->hide();
}

void BackgroundWidget::paintEvent(QPaintEvent * event) {
    QPainter p(this);
    p.drawPixmap(0, 0, mBgImage);
}

void BackgroundWidget::setBackgroundImage(const QString &imagePath) {
    mBackgroundImage = imagePath;
    QPixmap image(SYSFILE(imagePath));
    if(image.isNull()) {
        APPWARAING << "background image " << SYSFILE(imagePath) << "is null";
        return;
    }
    mBgImage = image.scaled(this->geometry().width(),this->geometry().height());
    APPINFO << this->geometry() << SYSFILE(imagePath);
//    this->setBackgroundBrush(image.scaled(this->geometry().size()));
//    this->setStyleSheet("#bg_widget{ background-image: url(" + SYSFILE(imagePath) + ");}");
}


